package com.example.controller;

import com.example.cac409club.rest.RestResult;
import com.example.constant.ResultCodeConstant;
import com.example.dto.PostgraduateInfoDTO;
import com.example.entity.PostgraduateInfoDO;
import com.example.query.PostgraduateInfoQuery;
import com.example.service.PostgraduateInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "考研信息管理")
@RequestMapping("/postgraduate")
@RestController
public class PostgraduateInfoController {

    @Autowired
    private PostgraduateInfoService postgraduateInfoService;

    /**
     * 新增考研信息
     *
     * @param postgraduateInfoDTO 考研信息DTO
     * @return RestResult
     */
    @PostMapping("/add")
    @ApiOperation("新增考研信息")
    public RestResult<Boolean> addPostgraduateInfo(@RequestBody @Validated PostgraduateInfoDTO postgraduateInfoDTO) {
        Boolean result = postgraduateInfoService.addPostgraduateInfo(postgraduateInfoDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 更新考研信息
     *
     * @param postgraduateInfoDTO 考研信息DTO
     * @return RestResult
     */
    @PutMapping("/update")
    @ApiOperation("更新考研信息")
    public RestResult<Boolean> updatePostgraduateInfo(@RequestBody @Validated PostgraduateInfoDTO postgraduateInfoDTO) {
        Boolean result = postgraduateInfoService.updatePostgraduateInfo(postgraduateInfoDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 删除考研信息
     *
     * @param infoId 信息ID
     * @return RestResult
     */
    @DeleteMapping("/delete/{infoId}")
    @ApiOperation("删除考研信息")
    public RestResult<Boolean> deletePostgraduateInfo(@PathVariable Integer infoId) {
        Boolean result = postgraduateInfoService.deletePostgraduateInfo(infoId);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 查询考研信息
     *
     * @param postgraduateInfoQuery 查询条件
     * @return RestResult
     */
    @GetMapping("/info")
    @ApiOperation("查询考研信息")
    public RestResult<List<PostgraduateInfoDO>> getPostgraduateInfos(@Validated PostgraduateInfoQuery postgraduateInfoQuery) {
        List<PostgraduateInfoDO> result = postgraduateInfoService.getPostgraduateInfos(postgraduateInfoQuery);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 导入考研信息
     *
     * @param postgraduateInfoDTO 考研信息DTO
     * @return RestResult
     */
    @PostMapping("/import")
    @ApiOperation("导入考研信息")
    public RestResult<Boolean> importPostgraduateInfo(@RequestBody @Validated PostgraduateInfoDTO postgraduateInfoDTO) {
        Boolean result = postgraduateInfoService.importPostgraduateInfo(postgraduateInfoDTO.getFileId());
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 导出考研信息
     *
     * @param postgraduateInfoDTO 考研信息DTO
     * @return RestResult
     */
    @PostMapping("/export")
    @ApiOperation("导出考研信息")
    public RestResult<List<PostgraduateInfoDO>> exportPostgraduateInfos(@RequestBody @Validated PostgraduateInfoDTO postgraduateInfoDTO) {
        List<PostgraduateInfoDO> result = postgraduateInfoService.exportPostgraduateInfos(postgraduateInfoDTO.getInfoIds());
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }
}